Modernize transforms tutorial to torchvision v2 API#3861
Modernize transforms tutorial to torchvision v2 API#3861omkar-334 wants to merge 3 commits intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3861
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Claude finished @sekyondaMeta's task in 1m 2s —— View job Review of PR #3861
Overall: This is a clean, well-scoped modernization. The changes correctly migrate from the deprecated Looks Good
Minor Suggestions (non-blocking)
VerdictThe PR is correct, well-motivated, and addresses issue #3853. The suggestions above are minor polish — this is ready to merge as-is. |
|
@omkar-334 Generally looks good, but can you fix the nits mentioned in the review above: Line 38 is long (~100 chars) — Consider breaking the target_transform lambda across lines for readability, though this is a style preference and the current form is acceptable for a tutorial: target_transform=v2.Lambda( import torch.nn.functional as F — The PR uses torch.nn.functional.one_hot inline (twice). A common pattern in PyTorch tutorials is import torch.nn.functional as F and then F.one_hot(...). This would shorten the lambda and match conventions used elsewhere in PyTorch docs. However, since this tutorial is minimal and doesn't use F for anything else, the fully qualified name is also fine. Further Reading link — The "Further Reading" section at line 70 still links to the general transforms page. Consider adding or replacing with a direct link to the v2 transforms getting started guide for readers who want to explore the new API further. |
|
hi @sekyondaMeta thanks for the review. i've applied the concerned changes and updated the branch... |
Fixes #3853
Description
files changed -
beginner_source/basics/transforms_tutorial.pytorchvision.transforms.ToTensor(deprecated since torchvision 0.16) with the v2 pipelinev2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)]).transformsnamespace import tofrom torchvision.transforms import v2.torch.zeros(...).scatter_(...)one-hot pattern withtorch.nn.functional.one_hot(torch.tensor(y), num_classes=10).float(), wrapped inv2.Lambda.v2.ToImage()+v2.ToDtype()andF.one_hotinstead ofToTensorandscatter_.Checklist
cc @subramen